

import javax.swing.*;
import java.awt.*;
import java.awt.event.*; 
import java.text.DecimalFormat;

import java.util.*;

import javax.media.opengl.*;
import com.jogamp.opengl.util.*;    // for FPSAnimator


public class Project4 extends JFrame {

    private static int DEFAULT_FPS = 80;

    private static final int PWIDTH = 712; 
    private static final int PHEIGHT = 712;

    private Project4Listener listener;
    private FPSAnimator animator;
    private javax.media.opengl.awt.GLCanvas canvas;


    public Project4() {
        super("Project 4");

        Container c = getContentPane();
        c.setLayout( new BorderLayout() );
        JPanel p = makeRenderPanel();
        c.add(p, BorderLayout.CENTER);

        addWindowListener( new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                /* The animator must be stopped in a different thread from
                the AWT event queue, to make sure that it completes before
                exit is called. */
                new Thread( new Runnable() {
                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            } // end of windowClosing()
        });
	 
        pack();
        setLocationRelativeTo(null);	 
        setVisible(true);
        canvas.requestFocusInWindow();
        animator.start();
    } 


    private JPanel makeRenderPanel() {
        /* Construct a GLCanvas in a JPanel, and add a 
        listener and animator. */

        JPanel renderPane = new JPanel(); 
        renderPane.setLayout( new BorderLayout() );
        renderPane.setOpaque(false);
        renderPane.setPreferredSize( new Dimension(PWIDTH, PHEIGHT));
    
        canvas = new javax.media.opengl.awt.GLCanvas();
        listener = new Project4Listener(); 
        listener.setCanvas(canvas);
        canvas.addGLEventListener(listener);
        canvas.addKeyListener(listener);

        animator = new FPSAnimator(canvas, DEFAULT_FPS, true); 

        renderPane.add(canvas, BorderLayout.CENTER);
        return renderPane;
    }  


    public static void main(String[] args) {  
        new Project4(); 
    }  



} 
